#include <bits/stdc++.h>
using namespace std;
class Tnode {
public:
  double data;
  Tnode *pLchild;
  Tnode *pRchild;
  Tnode(int d, Tnode *l = nullptr, Tnode *r = nullptr) {
    data = d;
    pLchild = l;
    pRchild = r;
  }
};
bool isEqual(double &a, double &b) {
  if (abs(a - b) <= 10e-10)
    return true;
  else
    return false;
}
bool doJudge(Tnode *root1, Tnode *root2) {
  if (!root2)
    return true; //访问到子数末尾
  if (!root1)    //空节点的异常处理
    return false;
  if (!isEqual(root1->data, root2->data))
    return false;
  else
    return doJudge(root1->pLchild, root2->pLchild) &&
           doJudge(root1->pRchild, root2->pRchild);
}
bool isSubTree(Tnode *root1, Tnode *root2) {
  bool result = false;
  if (root1 && root2) {
    if (isEqual(root1->data, root2->data))
      result = doJudge(root1, root2);
    if (!result)
      result =
          isSubTree(root1->pLchild, root2) || isSubTree(root1->pRchild, root2);
  }
  return result;
}
int main() {
  Tnode *a = new Tnode(8);
  Tnode *b = new Tnode(8);
  Tnode *c = new Tnode(7);
  Tnode *d = new Tnode(9);
  Tnode *e = new Tnode(2);
  Tnode *f = new Tnode(4);
  Tnode *g = new Tnode(7);

  Tnode *a1 = new Tnode(8);
  Tnode *b1 = new Tnode(9);
  Tnode *c1 = new Tnode(2);
  a->pLchild = b;
  a->pRchild = c;
  b->pLchild = d;
  b->pRchild = e;
  e->pLchild = f;
  e->pRchild = g;

  a1->pLchild = b1;
  a1->pRchild = c1;
  isSubTree(a, a1) ? cout << "是子树" : cout << "不是子数";
  delete a, b, c, d, e, f, g, a1, b1, c1;
  return 0;
}
